//#############################################################################
//#############################################################################
//This source file was written by Mert Dogar. If you have some questions about 
//the source code, please do not hesitate to ask me.
//The code is under GPL.
//Email: mertdogar@gmail.com , http://code.google.com/p/electron-cds
//#############################################################################
//#############################################################################

#include "component_port.h"

cport::cport(vector2 pos)
{
	position = pos;
	positionend = tovector2 (5,5);	
}

cport::cport()
{
	positionend = tovector2 (5,5);	

}

cport::~cport()
{
	
}
float cport::coscale(float rhs, float factor)
{
	return rhs*factor;
}
float cport::scale(float rhs, float factor)
{
	return rhs*factor;
}
void cport::draw(Cairo::RefPtr<Cairo::Context> cr, vector2 pos, float factor,int angle)
{
	cr->set_source_rgb(0.8,0.8,0.8);
	if(angle==0)
	{
		cr->move_to(scale(pos.x + position.x,factor), scale(pos.y + position.y,factor));
		cr->line_to(scale(pos.x + position.x + positionend.x,factor), scale(pos.y + position.y + positionend.y,factor));
		cr->move_to(scale(pos.x + position.x + positionend.x ,factor), scale(pos.y + position.y,factor));
		cr->line_to(scale(pos.x + position.x,factor),scale( pos.y + position.y + positionend.y,factor) );
	}
	else if(angle==1)
	{
		cr->move_to(scale(pos.x + position.y,factor), scale(pos.y + position.x,factor));
		cr->line_to(scale(pos.x + position.y + positionend.y,factor), scale(pos.y + position.x + positionend.x,factor));
		cr->move_to(scale(pos.x + position.y + positionend.y ,factor), scale(pos.y + position.x,factor));
		cr->line_to(scale(pos.x + position.y,factor),scale( pos.y + position.x + positionend.x,factor) );
	}

		cr->stroke();
}
bool cport::isonme(vector2 pos)
{
	if(pos.x < position.x + positionend.x && pos.x > position.x &&
	   pos.y < position.y + positionend.y && pos.y > position.y)
			return true;	
	return false;
}
